import logging
import os
import time

"""An unofficial Python wrapper for the OKEx exchange API v3

.. moduleauthor:: yxl

"""


def logger_error(error_message):
    logging.basicConfig(filename="log/test.log", filemode="a", format="%(asctime)s %(name)s:%(levelname)s:%(message)s",
                        datefmt="%d-%m-%Y %H:%M:%S", level=logging.DEBUG)
    logger = logging.getLogger('main')
    fh = logging.FileHandler('log/main.txt')
    fh.setLevel(logging.DEBUG)
    # create another handler output the log though console
    ch = logging.StreamHandler()
    ch.setLevel(logging.DEBUG)
    # 定义handler的输出格式
    formatter = logging.Formatter('%(asctime)s:%(levelname)s:%(message)s')
    fh.setFormatter(formatter)
    ch.setFormatter(formatter)
    # 给logger添加handler
    logger.addHandler(fh)
    logger.addHandler(ch)

    logger.error(error_message)


if __name__ == '__main__':
    logging.basicConfig(filename="log/test.log", filemode="a", format="%(asctime)s %(name)s:%(levelname)s:%(message)s",
                        datefmt="%d-%m-%Y %H:%M:%S", level=logging.DEBUG)
    logger = logging.getLogger('main')
    fh = logging.FileHandler('log/main.txt')
    fh.setLevel(logging.DEBUG)
    # create another handler output the log though console
    ch = logging.StreamHandler()
    ch.setLevel(logging.DEBUG)
    # 定义handler的输出格式
    formatter = logging.Formatter('%(asctime)s:%(levelname)s:%(message)s')
    fh.setFormatter(formatter)
    ch.setFormatter(formatter)
    # 给logger添加handler
    logger.addHandler(fh)
    logger.addHandler(ch)

    mes = 'yangxl 3'
    while True:
        logger.info(mes)
        logger.warning(mes)
        logger.error(mes)
        logger.debug(mes)
        print(mes)
        logger.debug(mes + 'end')
        print(mes + 'end')
        # fo = open("log/test.log", "r")
        size = os.path.getsize("log/test.log")
        fileSize = size / 1024 / 1024;
        print('There are %.3f' % fileSize, 'Mbytes in log/test.log')

        time.sleep(0.00001)

        if fileSize > 100:
            break
